<?php
namespace app\api\controller;
use think\Controller;
class Test extends Controller
{
    public function index(){
    }
    function curlData($url,$data,$method = 'GET',$type='json')
    {
        //初始化
        $ch = curl_init();
        $headers = [
            'form-data' => ['Content-Type: multipart/form-data'],
            'json'      => ['Content-Type: application/json'],
        ];
        if($method == 'GET'){
            if($data){
                $querystring = http_build_query($data);
                $url = $url.'?'.$querystring;
            }
        }
        // 请求头，可以传数组
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_HTTPHEADER,$headers[$type]);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);         // 执行后不直接打印出来
        if($method == 'POST'){
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');     // 请求方式
            curl_setopt($ch, CURLOPT_POST, true);               // post提交
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);              // post的变量
        }
        if($method == 'PUT'){
            curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");
            curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
        }
        if($method == 'DELETE'){
            curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
            curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
        }
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 不从证书中检查SSL加密算法是否存在
        $output = curl_exec($ch); //执行并获取HTML文档内容
        curl_close($ch); //释放curl句柄
        return $output;
    }
    public function test(){
        $this->db = new Sysdb;
        $mid = (int)input('get.mid');
        $menus = $this->db->table('admin_menus')->where(array('pid'=>$mid))->lists();
        //exit(dump($menus));
        // 返回上级菜单
        $backid = 0;
        if($mid > 0){
            $parent = $this->db->table('admin_menus')->where(array('pid'=>$mid))->item();
            $backid = $parent['pid'];
        }
        $this->assign('mid',$mid);
        $this->assign('backid',$backid);
        $this->assign('menus',$menus);
        return $this->fetch();



        exit(dump($menus));
        $title = '123';
        $value['values'] = json_encode($title);
        exit(dump($value));
        $title = '123';
        $res = $this->db->table('sites')->insert(array('names'=>'site','values'=>json_encode($title)));
        dump($res);
    }
    public function test2(){
        $this->db = new Sysdb;
        $pid = input('get.pid');
        $menus = $this->db->table('admin_menus')->where(array('pid'=>$pid))->lists();

        // 返回上级菜单
        $backid = 0;
        if($pid > 0){
            $parent = $this->db->table('admin_menus')->where(array('mid'=>$pid))->item();
            $backid = $parent['pid'];
        }

        $this->assign('pid',$pid);
        $this->assign('backid',$backid);
        $this->assign('data',$menus);
        return $this->fetch();
    }
    public function test3(){
        $this->db = new Sysdb;
        $this->db->table('admin_menus')->where(array('status'=>'1'))->update(['status'=>'0']);
    }
}